package main

import (
	"log"
	"yundian/internel/app/dao"
	"yundian/internel/pkg/dbs"
	"yundian/internel/pkg/dingo"
	"yundian/internel/pkg/dingo/global"
	"yundian/internel/pkg/utils"
)

func main() {
	dingo.InitViper("./configs/adm.yaml")
	dbs.NewMysqlComponent().Step()

	// 获取来宾帐号下的门店
	var datalb []int
	lists := GetPlaceIdsByUserIdCloseAD(406008)
	for _, lst := range lists {
		dao.NewPlaceDao().UpdatePlaceIsAdBanner(2, lst)
	}
	log.Println("修改总数：", len(datalb), datalb)

}

func GetPlaceIdsByUserIdCloseAD(loginUserId int) []int {
	placesBranchIds := dao.NewUserDao().GetPlacesId(loginUserId).Unwrap().([]int) // 查询用户ID下的所有关联门店
	userIdArr := dao.NewUserDao().QueryChildUserIds(loginUserId).Unwrap().([]int) // 查询用户ID下所有下级用户ID
	placeIdArr := dao.NewPlaceDao().GetPlaceByIds(userIdArr).Unwrap().([]int)     // 下级用户ID 下的门店
	placesBranchIds = append(placesBranchIds, placeIdArr...)                  // 合并门店
	placesIds := utils.RemoveRepByMap(placesBranchIds)                        // 去重门店

	var ids []int
	db := global.Orm.Debug().Table("places").Select("id")
	db.Where("id in (?)", placesIds)

	db.Find(&ids)
	return ids
}


